<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title>添加菜单</title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap-table.min.css" />
<style type="text/css">
body{	
	overflow:hidden;
}
</style>
<script type="text/javascript">
var menuId ="${menuId}";
$(function (){
	$("#addMenu").validationEngine({
		autoHidePrompt:true,//自动隐藏
		showOnMouseOver:true,//当鼠标移出时触发
		promptPosition:'bottomLeft',//提示信息的位置
		inlineValidation: true,//是否即时验证，false为提交表单时验证,默认true  
		failure : function() {
		    layer.message("验证失败，请检查");
			return false;  
		},//验证失败时调用的函数
		ajaxFormValidation: true,//开始AJAX验证
		success : function() {
		//	$("#addForm").submit();
		}//验证通过时调用的函数 
		//onAjaxFormComplete: ajaxValidationCallback
	});
	
	/* 提交 */
	$("#submit").click(function (){
		if($('#addMenu').validationEngine('validate')){
			$("#submit").unbind("click");
			var parentNameVal = $("#parentName").val();
			if(null == parentNameVal || parentNameVal==""){
				$("#parentId").val("");
			}
			var options = {
				dataType:"json",
				success:function(json){
					if(json.code == '1'){
						layer.msg(json.message,{shift:5,time:1000},function(){
							parent.refreshTable();
							parent.closeWin();
						});
					}
					if(json.code == '0'){
						window.location.href='${_baseUrl}/logout';
						//layer.msg(json.message);
					}
				},
				error:function(json){
					layer.msg("系统错误,请联系管理员");
				}
			};
			$('#addMenu').ajaxSubmit(options);
		}
	});
	
	$("#close").click(function (){
		parent.closeWin();
	});
});

function changetd(){
	var  parentId =$("#parentId").val();
	var path = "${_baseUrl}/kdtrMenuController/selectByParentId?menuId="+menuId+"&parentId="+parentId+"&random="+Math.random();
	layerIndex = layer.open({
		 type: 2,
		 title:'父菜单信息',
		 area: ['500px', '200px'],
		 fixed: false, //不固定
		 maxmin: true,
		 shim: true,
		 content: path,
		 success: function(){
			
		 },
		 moveEnd: function(layero){
			 
		 },
		 cancel: function(){ 
			 layer.closeAll();
		}
	});
	layer.full(layerIndex);
}

function sc(node) {//点击删除   删除当前元素
	var testProcedure = $(node).closest("tr");
	var tdArr = testProcedure.eq(0).find("input");
	tdArr.eq(0).val("");

}
</script>
</head>
<body>
<form action="${_baseUrl}/menu/insertMenu" id="addMenu" method="post">
<div style="width:98%;margin:auto">
	<table class="table table-bordered ofo submenu_table">
	  <tr>
	    <td height="50" width="15%" align="center"><span style="color: #f00">*</span> 菜单名称</td>
	    <td  width="35%" valign="middle"><div>
	    	<input type="text" name="menuName" id="menuName" value="${menuInfo.menuName }" <c:if test="${menuInfo != null }"><%--readonly="readonly"  disabled="disabled"--%></c:if> class="validate[required] nav_input"></div>
	    	<input type="hidden" id="menuId" name="menuId" value="${menuInfo.menuId }"/>
	    </td>
	    <td height="50" width="15%" align="center"><span style="color: #f00">*</span> 菜单请求地址</td>
	    <td  width="35%" valign="middle"><div>
	    	<input type="text" name="menuUrl" id="menuUrl" value="${menuInfo.menuUrl }" <c:if test="${menuInfo != null }"><%--readonly="readonly"  disabled="disabled"--%></c:if> class="validate[required] nav_input"></div>
	    </td>
	  </tr>
	  <tr>
	    <td height="50" width="15%" align="center"><span style="color: #f00">*</span> 排序</td>
	    <td  width="35%" valign="middle"><div>
	    	<input type="text" name="menuSeq" id="menuSeq" value="${menuInfo.menuSeq }" class="validate[required,custom[integer]] nav_input"></div>
	    </td>
	    <td height="50" width="15%" align="center">样式</td>
	    <td  width="35%" valign="middle"><div>
	    	<input type="text" name="classType" id="classType" value="${menuInfo.classType }" class="nav_input"></div>
	    </td>
	  </tr>
	  <tr>
	    <td height="50" width="15%" align="center">父菜单</td>
	    <td  width="35%" valign="middle">
	    	<%--<input type="text" name="parentName" id="parentName" value="${menuInfo.parentName}" class="nav_input"  onClick="changetd();">--%>
	    <%-- 	<select class="qr_select" id="parentId" name="parentId" style="width:50%;">
	    		<option value="">请选择父节点</option>
	    		<c:forEach items="${firstMenuList}" var="menu">
					<option value="${menu.menuId}" <c:if test="${menu.menuId == menuInfo.parentId}">selected="selected"</c:if> >${menu.menuName }</option>
				</c:forEach>
	      </select>
	       <a href="javascript:;" style="width:30%;margin-left: 170px;margin-top: -27px;" class="per_baocun" onClick="changetd();">选择</a> --%>

				<div class="upload" style="position: relative;">
				<input type="text" name="parentName" id="parentName" value="${menuInfo.parentName}" class="nav_input"  onClick="changetd();">
				<input type="hidden" name="parentId" id="parentId" value="${menuInfo.parentId}" class="nav_input">
				 <a class="upload_delete" href="javascript:void(0);" onclick='sc(this)'></a>
	      </div>
	    </td>
	    <td height="50" width="15%" align="center">&nbsp;</td>
	    <td  width="35%" valign="middle">&nbsp;</td>
      </tr>
	</table>
</div>

<div class="permission_an mubanclass_an ma mt30">
	<shiro:hasPermission name="menu:insertMenu">
        <a href="javascript:;" class="per_baocun" id="submit">保 存</a>
    </shiro:hasPermission>
	<shiro:hasPermission name="menu:close1">
		<a href="javascript:;" class="per_gbi" id="close">关 闭</a>
	</shiro:hasPermission>

	</div>
</form>

</body>
</html>